package com.UnionPayCenter.account.enums;

import com.UnionPayCenter.enums.CodeBaseEnum;
import com.UnionPayCenter.enums.ErrorCodeEnum;
import com.UnionPayCenter.exception.ApiException;

public enum AccountErrorCodeEnum implements CodeBaseEnum {


    ACCOUNT_TYPE_NOT_EXIST(44001, "店铺的账户类型不存在"),
    ACCOUNT_NOT_EXIST(44002, "账户不存在"),
    ACCOUNT_BALANCE(44003, "余额不足"),
    ACCOUNT_EXCEPTION(44004, "账户异常"),
    ACCOUNT_CAS_TIMEOUT(44005, "操作超时，请稍后再试"),
    ACCOUNT_SN_NOT_EXIST(44006, "流水号不存在，请核对"),
    ACCOUNT_PAY_CHANNEL_NOT_EXIST(44007, "支付渠道不存在，请核对"),
    ACCOUNT_CHARGE_BILL_NOT_EXIST(44008, "充值流水不存在，请核对"),
    ;


    private int code;

    private String msg;

    /**
     * Msg string.
     *
     * @return the string
     */
    public String msg() {
        return msg;
    }

    /**
     * Code int.
     *
     * @return the int
     */
    public int code() {
        return code;
    }

    public void exception() {
        throw new ApiException(code, msg);
    }

    AccountErrorCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * Gets enum.
     *
     * @param code the code
     * @return the enum
     */
    public static ErrorCodeEnum getEnum(int code) {
        for (ErrorCodeEnum ele : ErrorCodeEnum.values()) {
            if (ele.code() == code) {
                return ele;
            }
        }
        return null;
    }
}
